<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="Cache-Control" content="max-age=36000"/>
    <meta http-equiv="expires" content="Mon, 23 Jan 2099 12:52:30 GMT"/>
    <meta http-equiv="Pragma" content="private">
    <meta http-equiv="Cache" content="no-cache">

    <title>無心道--BI</title>
    <link rel="stylesheet" type="text/css" href="style/public.css"/>
    <script charset="utf-8" type="text/javascript" src="/js/base64.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/query-map.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/ajax-1.1.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/public.js"></script>
    <script charset="utf-8" type="application/javascript">
        var firstTitle = null;
        window.onload = async function () {
            let urlQuery = new QueryMap();
            urlQuery.loadUrl();

            await Ajax.post("/appinfo/queryAll", "",
                (response) => {
                    let responseText = response.responseText;
                    let evalJson = JSON.parse(responseText);
                    if (evalJson.code !== 0) {
                        console.info("code：" + evalJson.code + ", message：" + evalJson.msg);
                        if (evalJson.code === 99) {
                            alert("登录失效，重新登录")
                            top.location.href = "login.html";
                        }
                    } else {
                        let selectElement = $("select_appinfo");
                        selectElement.innerHTML = '';
                        for (const rowIndex in evalJson.data) {
                            let row = evalJson.data[rowIndex];
                            let optionElement = document.createElement("option");
                            optionElement.value = row[0];
                            optionElement.innerText = row[0] + '----' + row[1];
                            optionElement.title = row[2];
                            selectElement.appendChild(optionElement);
                        }
                    }
                }
            );
            let appId = urlQuery.get('appId');
            if (isNull(appId)) {
                urlQuery.put('appId', getSelectValue("select_appinfo"));
            }
            await Ajax.post("/query/allDataName", urlQuery.toString(),
                (response) => {
                    let responseText = response.responseText;
                    let evalJson = JSON.parse(responseText);
                    if (evalJson.code !== 0) {
                        console.info("code：" + evalJson.code + ", message：" + evalJson.msg);
                        if (evalJson.code === 99) {
                            alert("登录失效，重新登录")
                            top.location.href = "login.html";
                        }
                    } else {
                        for (const group in evalJson.data) {
                            {
                                let listElement = document.createElement("ul");
                                let element = document.createElement("li");
                                element.setAttribute("style", 'text-align: center; font-size: 18px')
                                element.innerHTML = group + '&nbsp;&nbsp;&nbsp;&nbsp;';
                                listElement.appendChild(element);
                                $("div_left_title").appendChild(listElement);
                            }
                            let list = evalJson.data[group];
                            {
                                let listElement = document.createElement("ul");
                                listElement.className = 'title';
                                for (let index in list) {
                                    let li = document.createElement("li");
                                    li.id = "li_log_" + index;
                                    li.setAttribute("title", list[index] + "(" + index + ")");
                                    li.setAttribute("onclick", "changePage('li_log_" + index + "', 'query-log.html', '', '" + index + "')");
                                    li.innerText = list[index];
                                    listElement.appendChild(li);
                                    if (firstTitle === null) {
                                        firstTitle = li;
                                    }
                                }
                                $("div_left_title").appendChild(listElement);
                            }
                        }
                    }
                }
            );

            let queryVariable = urlQuery.get("li");
            if (!isNull(queryVariable)) {
                let $1 = $(queryVariable);
                if (!isNull($1)) {
                    firstTitle = $1;
                }
            }
            firstTitle.className = "hover";
            firstTitle.click();
            closeLoading();
        }

        /*切换查询*/
        function changePage(li, page, urlPrefix, tableName) {
            openLoading();
            let urlQuery = new QueryMap();
            urlQuery.loadUrl();

            let appId = urlQuery.get("appId");

            if (urlQuery.get("li") !== li) {
                urlQuery.ps = {};
            }

            if (isNull(appId)) {
                urlQuery.put('appId', getSelectValue("select_appinfo"));
            } else {
                urlQuery.put("appId", appId);
            }

            urlQuery.put("li", li);

            if (!isNull(urlPrefix)) {
                urlQuery.put("urlPrefix", urlPrefix);
            }

            if (!isNull(tableName)) {
                urlQuery.put("tableName", tableName);
            }
            let newUrl = top.location.href.split("?")[0] + "?" + urlQuery.toString();
            top.history.pushState(null, null, newUrl);/*向当前url添加参数*/
            $("iframeContent").src = page;
            let leftChildren = $("div_body_left").children;
            let arrLeft = Array.from(leftChildren);
            for (let leftIndex in arrLeft) {
                let titleElement = arrLeft[leftIndex];
                let ulChildren = titleElement.children;
                let arrUl = Array.from(ulChildren)
                for (let ulIndex in arrUl) {
                    let ulElement = arrUl[ulIndex];
                    let liChildren = ulElement.children;
                    let arrLi = Array.from(liChildren)
                    for (let liIndex in arrLi) {
                        let liElement = arrLi[liIndex];
                        liElement.className = "";
                        if (liElement.id === li) {
                            liElement.className = "hover";
                        }
                    }
                }
            }
        }

        function changeAppInfo(sel) {
            openLoading();
            let newUrl = top.location.href.split("?")[0] + "?appId=" + sel.options[sel.selectedIndex].value;
            top.history.pushState(null, null, newUrl);/*向当前url添加参数*/
            firstTitle.click();
        }

    </script>
</head>
<body>
<div id="div_body_left" class="div_body_left">
    <div class="div_left_user">
        <ul>
            <li style="text-align: center; font-size: 18px">管理员&nbsp;&nbsp;&nbsp;&nbsp;</li>
        </ul>
        <ul id="ul_user" class="title">
            <li id="li_admin" onclick="changePage('li_admin','admin.html','','')">Admin</li>
        </ul>
        <ul>
            <li>应用管理&nbsp;&nbsp;</li>
        </ul>
        <ul class="title">
            <li>
                <SELECT id="select_appinfo"
                        style="width: 85%;background-color: #3b3b3b;color: white;"
                        onchange="changeAppInfo(this)">
                    <option value="10001" title="222">10001</option>
                    <option value="10002">10002</option>
                </SELECT>
            </li>
            <li id="li_appinfos" onclick="changePage('li_appinfos','query-log.html','appinfo','')">应用查询</li>
            <li id="li_addapp" onclick="changePage('li_addapp','addapp.html','appinfo','')">添加应用</li>
        </ul>
    </div>
    <div id="div_left_title" class="div_left_title">

    </div>
</div>
<div class="div_body_right">
    <iframe id="iframeContent" src=""
            style="border: 0px;width: 100%;height: 100%; overflow: hidden;"></iframe>
</div>
<div id="div_loading"
     style="width: 100%; height: 100%; display: inline-block; position: fixed; left: 0px; top: 0; right: 0px; bottom: 0px; float: left; z-index: 9999;">
    <div style="width: 100%; height: 100%; display: inline-block; position: fixed; left: 0px; top: 0; right: 0px; bottom: 0px; background-color: black; filter: alpha(Opacity=30); -moz-opacity: 0.3; opacity: 0.3; float: left; z-index: 9998;">
    </div>
    <div style="text-align: center; width: 200px; height: 190px; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); background-color: white; z-index: 9999;">
        <img src="/loading4.gif" style="width: 200px; height: 150px;"/>
        <br/>
        <input type="button" onclick='closeLoading();' value="关闭"/>
    </div>
</div>
</body>
</html>